package smartcode.util;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.aliang.auto.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import app.auto.AndroidInstance;

public class ParaAlert extends AndroidInstance {
    private ListView listview;

    public ListView getListview() {
        return listview;
    }

    public ParaAlert setListview(ListView listview) {
        this.listview = listview;
        return this;
    }

    /***
     *
     * @param listView
     */
    public ParaAlert alert(ListView listView, List listparam) {
        if (listView == null) {
            listView = new ListView(getContext());

        }
        if (listparam != null) {
            list = listparam;
        }
        this.listview = listView;
        listView.setAdapter(new BaseAdapter() {
            @Override
            public int getCount() {
                return list.size();
            }

            @Override
            public Object getItem(int position) {
                return list.get(position);
            }

            @Override
            public long getItemId(int position) {
                return 0;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                if (convertView == null) {
                    convertView = LayoutInflater.from(getContext()).inflate(R.layout.map_dialog_item, null);
                }
                Map m = (Map) getItem(position);

                ((TextView) convertView.findViewById(R.id.type)).setText((CharSequence) m.get("vartype"));
                ((TextView) convertView.findViewById(R.id.focus)).setText((CharSequence) m.get("varname"));

                return convertView;
            }
        });
        return this;
    }

    public List list = new ArrayList();

    public ParaAlert setList(List list) {
        this.list = list;
        ((BaseAdapter) listview.getAdapter()).notifyDataSetChanged();
        return this;
    }

    @Override
    public AndroidInstance use(Object mp, Object... p) {
        return null;
    }
}
